package pl.myapp.webtest.rest;

import org.slf4j.Logger;
import pl.myapp.webtest.config.qualifier.MyLogger;
import pl.myapp.webtest.rest.xml.User;
import pl.myapp.webtest.rest.xml.UserData;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: kaafaar
 * Date: 15.05.11
 * Time: 00:32
 * To change this template use File | Settings | File Templates.
 */
@Path( "hello-rest" )
@RequestScoped
public class HelloRest implements Serializable {

    @Inject
	@MyLogger
    Logger logger;

    @GET
    @Path("/test-get/{id}")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public User testget(@PathParam("id") Long id) {

       logger.info("metoda get, odebralem:"+id);

       return new User("Marek", "500123456", "Sopot", "Poland", new UserData("pesel", "secretid"));
    }

	@GET
	@Path("/custom-path/")
	@Produces(MediaType.TEXT_PLAIN)
	public String getsome() {
		return "aaaaaaa";
	}

	// curl -H "Accept: application/json" -H "Content-Type: application/xml" -d "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><user><name>Marek</name><phone>500123456</phone><city>Sopot</city><country>Poland</country></user>" http://localhost:8080/webtest-hello/rest/hello-rest/test-xml
	@POST
	@Path("/test-xml/")
    @Consumes(MediaType.APPLICATION_XML)
	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public User store(User user){
        System.out.println("User: " + user.toString());
		user.setName("uzytkownik ze zmieniona nazwa w odpowiedzi !");
        return user;
    }
}